#include <reg52.h>
#define uint unsigned int
sbit analog=P2^3;
uchar ad_c;
void delay(void);
void delay5ms(void);
void xs(uint num,uchar wz,uint t);
void display(uchar qian,uchar bai,uchar shi,uchar ge,uchar cyc,uchar time);
void main()
{
	while(1)
	{
		analog=1;
		while(!analog)
		{
			ad_c++;
			delay();
		}
		analog=0;
		delay5ms();
		xs(ad_c,0,100)
	}
}
void delay(void)   //?? -0.125us
{
    unsigned char a,b;
    for(b=190;b>0;b--)
        for(a=2;a>0;a--);
}
void delay5ms(void)   //?? -0.125us
{
    unsigned char a,b;
    for(b=86;b>0;b--)
        for(a=76;a>0;a--);
}
/*****************************************
							????
????????? display??
num=?? wz=????? t??????(??)
if(num/1000==0)	??????????
switch(b)				??????????
ge=table[ge];		???????16??
switch(wz)			?????
shownum(qian		????.??
****************************************/
void xs(uint num,uchar wz,uint t)
{
	uchar b=4;
	uchar qian,bai,shi,ge;
	if(num/1000==0)
	{
		b--;
		if(num%1000/100==0)
		{
			b--;
			if(num%100/10==0)
			{b--;}
		}
	}
	switch(b)
	{
		case 1:
			{
				ge=num%10;
				shi=0xff;
				bai=0xff;
				qian=0xff;
				break;
			}
		case 2:
			{
				ge=num%10;
				shi=num%100/10;
				bai=0xff;
				qian=0xff;
				break;
			}
		case 3:
			{
				ge=num%10;
				shi=num%100/10;
				bai=num%1000/100;
				qian=0xff;
				break;
			}
		case 4:
			{
				ge=num%10;
				shi=num%100/10;
				bai=num%1000/100;
				qian=num/1000;
				break;
			}
		default:
			{
				qian=0xFF;
				bai=0x86;
				shi=0xAF;
				ge=0xAF;
				break;
			}
	}
	ge=smgsz[ge];
	shi=smgsz[shi];
	bai=smgsz[bai];
	qian=smgsz[qian];
	switch(wz)
	{
		case 1:
		{
			ge-=0x80;
			break;
		}
		case 2:
		{
			shi-=0x80;
			break;
		}
		case 3:
		{
			bai-=0x80;
			break;
		}
		case 4:
		{
			qian-=0x80;
			break;
		}
		default:
		{
			break;
		}
	}
		display(qian,bai,shi,ge,t,1);
}
void display(uchar qian,uchar bai,uchar shi,uchar ge,uchar cyc,uchar time)
{
uchar xh;
for(xh=0;xh<cyc;xh++)
		{
			P0=qian;//????
			P20=0;
			delay(time);
			P20=1;
			P0=bai;//????
			P21=0;
			delay(time);
			P21=1;
			P0=shi;//????
			P22=0;
			delay(time);
			P22=1;
			P0=ge;//????
			P23=0;
			delay(time);
			P23=1;
		}
}
